﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using dhsystem.Main;
using dhSystemBLL.orderData;
using baseSet.importExport;
using dhDataAcess.dataAcess;
using dhDataAcess.dataAcess.orderDataSetTableAdapters;
using baseSet.power;

namespace dhsystem.orderForm
{
    public partial class FrmscrlMaster : Form
    {

        scrlBLL scrl = new scrlBLL();
        string state;
        public FrmscrlMaster()
        {
            InitializeComponent();
        }
        //打开窗口时显示列表数据
        private void FrmscrlMaster_Load(object sender, EventArgs e)
        {
            getData();
        }
        //新增按钮，显示新增数据组件
        private void toolAdd_Click(object sender, EventArgs e)
        {
            state = "新增";
            FrmscrlMasterAdd scrlMasterAdd = new FrmscrlMasterAdd(bindingSourcescrlMaster, state);
            scrlMasterAdd.ShowDialog();
            scrlMasterAdd.Owner = this;
        }
        //工具栏查询按钮，查询所有列表数据
        private void toolQuery_Click(object sender, EventArgs e)
        {
            FrmDataQuery query = new FrmDataQuery(moduleInfo.scrlMaster );
            DialogResult result = query.ShowDialog();
            if (result == DialogResult.Yes)
            {
                dGridorderDetail .DataSource  = query.rTable;
            }
        }
        //工具栏的编辑按钮,修改数据
        private void toolEdit_Click(object sender, EventArgs e)
        {

            state = "编辑";
            FrmscrlMasterAdd scrlMasterAdd = new FrmscrlMasterAdd(bindingSourcescrlMaster, state);
            scrlMasterAdd.ShowDialog();
        }
        //删除按钮，删除选中行数据
        private void toolDel_Click(object sender, EventArgs e)
        {

            string billNo = dGridorderMaster.Rows[dGridorderMaster.CurrentRow.Index].Cells[1].Value.ToString();
            try
            {
                DialogResult result = MessageBox.Show("是否删除：" + billNo + "！", "提示信息", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {

                    bindingSourcescrlMaster.DataSource = scrl.scrlMasterDel(billNo);

                }
                getData();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }
        //查询按钮，按条件查询数据
        private void buttonQuery_Click(object sender, EventArgs e)
        {

        }
        //刷新按钮
        private void buttupdate_Click(object sender, EventArgs e)
        {
            getData();
        }
        //工具栏退出按钮，退出窗口
        private void toolExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        //datagridview第一列显示行号
        private void dGridorderMaster_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
        {
            e.Row.HeaderCell.Value = string.Format("{0}", e.Row.Index + 1);
        }
        private void getData()
        {
            scrlDetailTableAdapter scrlDetailAdapter = new scrlDetailTableAdapter();
            scrlMasterTableAdapter scrlMasterAdapter = new scrlMasterTableAdapter();
            orderDataSet scrl = new orderDataSet();
            scrlDetailAdapter.FillscrlDetailALL (scrl.scrlDetail);
            scrlMasterAdapter.FillscrlMasterALL (scrl.scrlMaster);
            bindingSourcescrlMaster.DataSource = scrl;
            bindingSourcescrlMaster.DataMember = "scrlMaster";
            dGridorderMaster .DataSource  = bindingSourcescrlMaster ;

            DcolumnSet.colSet(moduleInfo.scrlMaster , dGridorderMaster );
            toolStripStatusLabel1.Text = "领料主表数据总条数:" + dGridorderMaster.RowCount.ToString() + "条";
            bindingSourcescrlDetail .DataSource = bindingSourcescrlMaster ;

            bindingSourcescrlDetail.DataMember = "fk_scrlDetail_billNo";
            dGridorderDetail.DataSource = bindingSourcescrlDetail;
            DcolumnSet.colSet(moduleInfo.scrlDetail , dGridorderDetail );
            toolStripStatusLabel3.Text = "领料从表数据总条数:" + dGridorderDetail.RowCount.ToString() + "条";

            sysDataSet.modulAaccessDataTable modulAaccess = powerSet.modulPower(moduleInfo.scrlMaster );
            foreach (sysDataSet.modulAaccessRow modulAaccessRow in modulAaccess)
            {
                buttonQuery.Enabled = modulAaccessRow.showAc;
                toolAdd.Enabled = modulAaccessRow.addAc;
                toolEdit.Enabled = modulAaccessRow.editAc;
                toolDel.Enabled = modulAaccessRow.delAc;
                toolPrint.Enabled = modulAaccessRow.printAc;
                toolExport.Enabled = modulAaccessRow.exportAc;
                //buttImport.Enabled = modulAaccessRow.importAc;

            }
        }
        //datagridview第一列显示行号
        private void dGridorderDetail_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
        {
            e.Row.HeaderCell.Value = string.Format("{0}", e.Row.Index + 1);
        }

        private void buttImport_Click(object sender, EventArgs e)
        {

        }

        private void toolExport_Click(object sender, EventArgs e)
        {
            FrmExcelExport frm = new FrmExcelExport(moduleInfo.scrlMaster , dGridorderMaster , "生产领料信息");
            frm.ShowDialog();
        }

        private void toolSave_Click(object sender, EventArgs e)
        {

        }
      
   }

}
